<%@ page import="dart.Game" %>
<% colWidth = 93 / (game.playerGames.size())

currentRound = game.currentRound;
numRows = numRows as Integer ?: currentRound + 2
def begin = (currentRound > numRows ? currentRound - numRows : 0)
turnRange = (begin..<currentRound)
showCurrent = (game.status != Game.COMPLETED)

playerRange = (0..<game.playerGames.size());
scoreTable = game.scoreTable();
%>

<table id="rounds" cellspacing="0">
	<thead>
	<tr>
		<th width="7%" class="roundNum"></th>
		<g:each in="${game.playerGames}" var="playerGame" status="i">
			<th width="${colWidth}%" class="player ${i == game.currentPlayer ? 'currentPlayer' : ''} "
					style="${playerGame.person.style()}">
				${playerGame.person.displayName}
			</th>
		</g:each>
	</tr>
	</thead>
	<tbody>

	<g:each in="${turnRange}" var="round">
		<tr class="${(round % 2) ? 'odd' : 'even'}">
			<td class="roundNum">${round}</td>
			<g:each in="${playerRange}" var="i">
				<td class="${i == game.currentPlayer ? 'currentPlayer' : ''}">
					${scoreTable[i][round]}
				</td>
			</g:each>
		</tr>
	</g:each>

	<g:if test="${showCurrent}">
		<tr class="currentRound">
			<td class="roundNum">${currentRound}</td>
			<g:each in="${playerRange}" var="i">
				<td class="${i == game.currentPlayer ? 'currentPlayer' : ''}"
						id="${i == game.currentPlayer ? 'scoreFinal' : ''}">
					<g:if test="${i < game.currentPlayer}">
						${scoreTable[i][currentRound]}
					</g:if><g:elseif test="${i == game.currentPlayer}">
						${scoreTable[i][currentRound-1]}
					</g:elseif>
				</td>
			</g:each>
		</tr>
	</g:if>
	</tbody>
</table>